<!-- Usage: https://github.com/xianmin/hugo-theme-jane/issues/62 -->

<!-- reset scratch variables at the start -->
{{ $.Scratch.Set "seriesName" false }}
{{ $.Scratch.Set "tagName" false }}
{{ $.Scratch.Set "categoryName" false }}

{{ if .IsNamedParams }}
  {{ $.Scratch.Set "tagName" (.Get "tag") }}
  {{ $.Scratch.Set "categoryName" (.Get "category") }}
{{ else }}
  <!-- get series -->
  {{ $.Scratch.Set "seriesName" (.Get 0) }}
{{ end }}

<ul>
  {{ with $.Scratch.Get "seriesName" }}
  <!-- default series list -->
    {{ range $name, $taxonomy := $.Site.Taxonomies.series }}
      {{ if eq $name ($.Scratch.Get "seriesName") }}
        {{ range $taxonomy.Pages.Reverse }}
          <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
        {{ end }}
      {{ end }}
    {{ end }}
  {{ else }}
  <!-- else set tag or cotegory -->
    {{ with $.Scratch.Get "tagName" }}
    <!-- tag list -->
      {{ range $name, $taxonomy := $.Site.Taxonomies.tags }}
        {{ if eq $name ($.Scratch.Get "tagName") }}
          {{ range $taxonomy.Pages.Reverse }}
            <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
          {{ end }}
        {{ end }}
      {{ end }}
    {{ end }}

    {{ with $.Scratch.Get "categoryName" }}
    <!-- category list -->
      {{ range $name, $taxonomy := $.Site.Taxonomies.categories }}
        {{ if eq $name ($.Scratch.Get "categoryName") }}
          {{ range $taxonomy.Pages.Reverse }}
            <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
          {{ end }}
        {{ end }}
      {{ end }}
    {{ end }}
  {{ end }}
</ul>
